<?php

namespace Biz\model\MijiaSmartKitchen;

use Biz\pockets\modelTrait\BizModelTrait;
use Doraemon\pockets\datebase\BaseDbModel;

class MiJiaSmartKitchenUser extends BaseDbModel
{
    const _CONFIG_FILE_ = 'db_store';

    const _CONFIG_SELECT_ = 'db_brand_activity';

    const _DATABASE_ = 'brand_activity';

    const _TABLE_NAME = 'mijia_smart_kitchen_user';

    use BizModelTrait;

    public static function getInfo($platform, $uuid)
    {
        $where = [
            'platform' => $platform,
            'uuid' => $uuid,
        ];
        return self::dataSelectInfo($where);
    }

    public static function exists($platform, $uuid)
    {
        $where = [
            'platform' => $platform,
            'uuid' => $uuid,
        ];
        return self::dataHas($where);
    }

    public static function record($platform, $uuid)
    {

        $data = [
            'platform' => $platform,
            'uuid' => $uuid,
            'times' => 1,
            'create_time' => date('Y-m-d H:i:s'),
        ];

        return self::dataInsert($data);
    }

    public static function expendTimes($platform, $uuid, $v)
    {
        $where = [
            'platform' => $platform,
            'uuid' => $uuid,
            'times[>]' => 0,
            'v' => $v,
        ];
        $data = [
            'times[-]' => 1,
            'v[+]' => 1,
            'update_time' => date('Y-m-d H:i:s')
        ];

        return self::dataUpdate($data, $where, true);
    }


}